package stat

import (
	db2 "data_summary/common/db"
	models "data_summary/common/models/stat"
	"gorm.io/gorm"
)

type StatTaskDao struct {
	db *gorm.DB
}

func NewStatTask(db *gorm.DB) *StatTaskDao {
	dao := &StatTaskDao{
		db: db,
	}
	return dao
}

// 添加
func (c *StatTaskDao) Create(v *models.StatTask) (id uint, err error) {
	err = c.db.Create(&v).Error
	return v.Id, err
}

// 修改
func (c *StatTaskDao) Update(v *models.StatTask) (id uint, err error) {
	err = c.db.Save(&v).Error
	return v.Id, err
}

// 删除
func (c *StatTaskDao) Delete(v *models.StatTask) (id uint, err error) {
	err = c.db.Delete(&v).Error
	return v.Id, err
}

func (c *StatTaskDao) Get(where map[string]interface{}, order string, page int, pageSize int) interface{} {
	var v []models.StatTask
	query := c.db.Where(where).Order(order).Scopes(db2.Paginate(page, pageSize))
	query.Find(&v)
	return v
}
